<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<style>
    .el-table .warning-row {
        background: oldlace;
    }

    .el-table .success-row {
        background: #f0f9eb;
    }
</style>
</body>
<div id="app">
    <!--    条件查询-->
    <el-form :inline="true" :model="brand" class="demo-form-inline">
        <el-form-item label="当前状态">
            <el-select v-model="brand.status" placeholder="当前状态">
                <el-option label="启用" value="1"></el-option>
                <el-option label="禁用" value="0"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="企业名称">
            <el-input v-model="brand.companyName" placeholder="企业名称"></el-input>
        </el-form-item>
        <el-form-item label="品牌名称">
            <el-input v-model="brand.brandName" placeholder="品牌名称"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="search">查询</el-button>
        </el-form-item>
    </el-form>
    <!-- -->
    <el-row>
        <el-button type="danger" plain>批量删除</el-button>
        <el-button type="primary" plain @click="dialogVisible = true">新增</el-button>
    </el-row>
    <!--    新增对话框-->
    <el-dialog
            title="提示"
            :visible.sync="dialogVisible"
            width="30%"
    >
        <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="品牌名称">
                <el-input v-model="addbrand.brandName"></el-input>
            </el-form-item>
            <el-form-item label="企业名称">
                <el-input v-model="addbrand.companyName"></el-input>
            </el-form-item>
            <el-form-item label="排序">
                <el-input v-model="addbrand.ordered"></el-input>
            </el-form-item>
            <el-form-item label="描述">
                <el-input type="textarea" v-model="addbrand.description"></el-input>
            </el-form-item>
            <el-form-item label="状态">
                <el-switch v-model="addbrand.status"
                           active-value="1"
                           inactive-value="0"
                >
                </el-switch>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="add">提交</el-button>
                <el-button @click="dialogVisible = false">取消</el-button>
            </el-form-item>
        </el-form>
        </span>
    </el-dialog>
    <!--    数据表单-->
    <el-table
            :data="tableData"
            style="width: 100%"
            :row-class-name="tableRowClassName"
            @selection-change="handleSelectionChange">

        <el-table-column
                type="selection"
                width="55">
        </el-table-column>
        <el-table-column
                type="index"
                width="50">
        </el-table-column>
        <el-table-column
                prop="brandName"
                label="品牌名称"
                align="center"
        >
        </el-table-column>
        <el-table-column
                prop="companyName"
                label="企业名称"
                align="center"
        >
        </el-table-column>
        <el-table-column
                prop="ordered"
                label="排序"
                align="center"
        >
        </el-table-column>
        <el-table-column
                prop="status"
                label="当前状态"
                align="center"
        >
        </el-table-column>
        <el-table-column
                label="操作"
                align="center"
        >
            <el-row>
                <el-button type="primary">修改</el-button>
                <el-button type="danger">删除</el-button>
            </el-row>
        </el-table-column>
    </el-table>
    <!--    分页工具条-->
    <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage4"
            :page-sizes="[100, 200, 300, 400]"
            :page-size="100"
            layout="total, sizes, prev, pager, next, jumper"
            :total="400">
    </el-pagination>
</div>

<script src="js/vue.js"></script>
<script src="element-ui/lib/index.js"></script>
<link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css">
<script src="js/axios-0.18.0.js"></script>
<script>
    new Vue({
        el: "#app",
        mounted() {
            this.selectAll()
        },
        methods: {
            tableRowClassName({row, rowIndex}) {
                if (rowIndex === 1) {
                    return 'warning-row';
                } else if (rowIndex === 3) {
                    return 'success-row';
                }
                return '';
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
                console.log(this.multipleSelection)
            },
            //条件查询
            search() {
                console.log(this.brand)
            },
            selectAll() {
                // 发送异步请求，查询所有数据
                axios({
                    method: "get",
                    url: "http://localhost:8088/mybound-demo/brandSelectAll"
                }).then(response => {
                    this.tableData = response.data;
                    console.log(response.data)
                })
            },
            //新增品牌
            add() {
                axios({
                    method: "post",
                    url: "http://localhost:8088/mybound-demo/add",
                    data:this.addbrand
                }).then(resp => {
                    if (resp.data == "success") {
                        this.$message({
                            message: '恭喜你，添加数据成功',
                            type: 'success'
                        });
                        this.dialogVisible = false;
                        this.selectAll()
                    }
                });
                console.log(this.addbrand);
                this.dialogVisible = false;
            },
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
            }
        },
        data() {
            return {
                currentPage4: 4,
                form: {
                    name: '',
                    region: '',
                    date1: '',
                    date2: '',
                    delivery: false,
                    type: [],
                    resource: '',
                    desc: ''
                },
                dialogVisible: false,
                brand: {
                    status: '', companyName: '', brandName: '', id: '', description: '', ordered: ''
                },
                addbrand: {
                    status: '', companyName: '', brandName: '', id: '', description: '', ordered: ''
                },
                multipleSelection: [],
                tableData: [{
                    brandName: '华为',
                    companyName: '有限公司',
                    ordered: '10',
                    status: '1'
                }, {
                    brandName: '华为',
                    companyName: '有限公司',
                    ordered: '20',
                    status: '1'
                }, {
                    brandName: '华为',
                    companyName: '有限公司',
                    ordered: '66',
                    status: '1'
                }, {
                    brandName: '华为',
                    companyName: '有限公司',
                    ordered: '88',
                    status: '1'
                }]
            }
        }
    });
</script>
</html>